package org.ktpro.shortlink.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.ktpro.shortlink.project.common.convention.result.Result;
import org.ktpro.shortlink.project.common.convention.result.Results;
import org.ktpro.shortlink.project.dto.req.RecycleBinRemoveReqDTO;
import org.ktpro.shortlink.project.dto.req.RecycleBinReqDTO;
import org.ktpro.shortlink.project.dto.req.ShortLinkRecycleBinPageReqDTO;
import org.ktpro.shortlink.project.dto.resp.ShortLinkPageRespDTO;
import org.ktpro.shortlink.project.service.RecycleBinService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 回收站控制层
 */
@RestController
@Slf4j
@RequiredArgsConstructor
public class RecycleBinController {

    private final RecycleBinService recycleBinService;

    /**
     * 短链接移进回收站
     */
    @Timed(value = "project-InRecycle", description = "短链接移入回收站")
    @PostMapping("/api/short-link/v1/recycle-bin/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinReqDTO requestParam){
        recycleBinService.saveRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 短链接移出回收站
     */
    @Timed(value = "project-OutRecycle", description = "短链接移出回收站")
    @PostMapping("/api/short-link/v1/recycle-bin/recover")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinReqDTO requestParam){
        recycleBinService.removeRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 回收站彻底删除短链接
     */
    @PostMapping("/api/short-link/v1/recycle-bin/remove")
    public Result<Void> removeFullyRecycleBin(@RequestBody RecycleBinRemoveReqDTO requestParam){
        recycleBinService.removeFullyRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 分页查询回收站短链接
     */
    @GetMapping("/api/short-link/v1/recycle-bin/page")
    public Result<IPage<ShortLinkPageRespDTO>> pageRecycleBinLinks(ShortLinkRecycleBinPageReqDTO requestParam){
        //接收一个列表，对该用户的所有分组进行查询，找到未启用的短链接
        return Results.success(recycleBinService.pageShortLink(requestParam));
    }
}
